import asyncio

from com.arcfox.base.base_spider import ExecuteType
from com.arcfox.school.processor.handcollege.hand_pheasant_college_processor import HandPheasantCollegeProcessor
from com.arcfox.school.spider.handcollege.hand_base_spider import HandBaseSpider
from com.arcfox.util import async_request as requests


class HandPheasantCollegeSpider(HandBaseSpider):
    def __init__(self, proxy=None):
        '''
        掌上高考野鸡大学数据抓取
        '''
        super().__init__()
        self.url = "https://static-data.gaokao.cn/www/2.0/school/informal.json"
        self.processor = HandPheasantCollegeProcessor()
        self.proxy = proxy

    async def _pull_task(self):
        return None, ExecuteType.ONCE

    async def _crawl_by_task(self, tasks):
        resp = await requests.get_with_session(self.url, headers=self.get_default_header(), timeout=5)
        if resp.code == 200:
            result_json = resp.json()
            await self.processor.parse_and_save_data(result_json)


if __name__ == "__main__":
    asyncio.run(HandPheasantCollegeSpider().start_crawl())
